﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

using com.diagnosis.tool.xml;


namespace Tester
{
    class Program
    {
        static void Main(string[] args)
        {
            DiagnosisToolXmlMngr mngr = DiagnosisToolXmlMngr.GetInstance(@"C:\projects\DiagnosisData.xml");
            
            DiagnosisToolData dtool = mngr.DiagnosisToolData;
            Disease d = dtool.Diseases.ElementAt(0);

            d.SymptomIDS = new Int32[1];
            d.SymptomIDS[0] = 1;

            //Disease d1 = new Disease();
            //d1.DiseaseName = "d1";
            //d1.Syptomps = new String[] { "s11", "s12" };

            //Disease d2 = new Disease();
            //d2.DiseaseName = "d2";
            //d2.Syptomps = new String[] { "s21", "s22" };

            //List<Disease> ds = new List<Disease>();
            //ds.Add(d1);
            //ds.Add(d2);

            //dtool.Diseases = ds;



            SerializeToXML(dtool);

            //Deserialize();

            //
            //Console.WriteLine(mngr._DiagnosisToolData.Diseases.Length);

            System.Threading.Thread.Sleep(2000);
        }

        static public void SerializeToXML(DiagnosisToolData pDtool)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(DiagnosisToolData));
            TextWriter textWriter = new StreamWriter(@"C:\projects\DiagnosisData.new.xml");
            serializer.Serialize(textWriter, pDtool);
            textWriter.Close();
        }

        static public DiagnosisToolData Deserialize()
        {
            DiagnosisToolData dtd = null;
            string path = @"C:\projects\movie.xml";

            XmlSerializer serializer = new XmlSerializer(typeof(DiagnosisToolData));

            StreamReader reader = new StreamReader(path);
            dtd = (DiagnosisToolData)serializer.Deserialize(reader);
            reader.Close();

            Console.WriteLine(dtd.Diseases.Length);

            System.Threading.Thread.Sleep(2000);

            return dtd;
        }  
    } 
}
